RewriteEngine On

# Force HTTPS and www-less canonical host (safe to remove the HTTPS rule on local dev)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

# Property detail: /properties/villa-in-nyarutarama
RewriteRule ^properties/([a-z0-9-]+)/?$ properties/detail.php?slug=$1 [L,QSA]

# Category landing: /category/villas
RewriteRule ^category/([a-z0-9-]+)/?$ category/index.php?slug=$1 [L,QSA]

# District/investment location landing: /district/nyarutarama
RewriteRule ^district/([a-z0-9-]+)/?$ district/index.php?slug=$1 [L,QSA]

# Blog article: /blog/off-plan-vs-completed
RewriteRule ^blog/([a-z0-9-]+)/?$ blog/detail.php?slug=$1&type=article [L,QSA]

# News article: /news/some-announcement
RewriteRule ^news/([a-z0-9-]+)/?$ blog/detail.php?slug=$1&type=news [L,QSA]

# Sitemap / robots
RewriteRule ^sitemap\.xml$ sitemap.php [L]

# Pretty static pages without .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)/?$ $1.php [L,QSA]

# Security: block access to sensitive paths
RewriteRule ^(sql|sql_backups|includes)/ - [F,L]

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/json image/svg+xml
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>

<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set X-Frame-Options "SAMEORIGIN"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

ErrorDocument 404 /404.php
Options -Indexes
